<template>
	<view class="content_all">
		<view class="content_1 content">
			<view class="hh">
				hello
			</view>
			<view style="margin-top: 20upx;font-size: 26upx;">欢迎来到桂民社区服务站</view>
			<view class="list">
				<view class="list-call">
					<i class="ri-tablet-line" style="color:#7800BE;font-size:14px;"></i>
					<!-- <i-icon size="26upx" color="#7800BE" name="tablet-line"></i-icon> -->
					<input class="biaoti" v-model="phoneno" type="number" maxlength="11" placeholder="输入手机号" />
				</view>
				<view class="list-call" style="margin-top: 20upx;">
					<i class="ri-lock-line" style="color:#7800BE;font-size:14px;"></i>
					<!-- <i-icon size="26upx" color="#7800BE" name="lock-line"></i-icon> -->
					<input class="biaoti" v-model="password" type="password" maxlength="20" placeholder="请输入密码" />
				</view>
			</view>
			<view style="width: 200px;">
				<button @click="login()">
					<i class="ri-shield-check-fill" style="color:#000;font-size:12px;"></i>
					<!-- <i-icon size="20upx" color="#000" name="shield-check-fill"></i-icon> -->
					登录
				</button>
			</view>
		</view>
		<view class="foot" style="text-align: center;line-height: 30px;">
			<view style="margin-right: 5upx;">Copyright © 2022 桂民社区服务站</view>
			<view>Powered by 奇果科技</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				phoneno: '',
				password: '',
				people: []
			};
		},
		methods: {
			/**
			 * 登录
			 */
			login() {
				var that = this
				let adminData = {
					"phone": that.phoneno,
					"password": that.password
				}
				if (that.phoneno == null || that.phoneno == '') {
					uni.showToast({
						title: "请输入手机号",
						duration: 2000,
					})
					return;
				}
				if (that.password == null || that.password == '') {
					uni.showToast({
						title: "请输入密码",
						duration: 2000,
					})
					return;
				}
				uni.showLoading({
					title: '登录中...'
				})
				uni.request({
					url: this.baseURL + '/admin/login',
					method: "POST",
					data: adminData,
					success: function(res) {
						console.log(res)
						if (res.data.success == true) {
							uni.hideLoading()
							//保存token
							uni.setStorageSync('token', res.data.data);
							if (res.data.code == 101) { //管理员
								uni.showToast({
									title: "登录成功",
									duration: 2000,
									icon: 'loading'
								})
								setTimeout(function() {
									uni.redirectTo({
										url: "../index/index"
									})
								}, 2000);
							}
							if (res.data.code == 102) { //物业
								uni.showToast({
									title: "登录成功",
									duration: 2000,
									icon: 'loading'
								})
								setTimeout(function() {
									uni.redirectTo({
										url: "../index/wyIndex"
									})
								}, 2000);
							}

						} else {
							uni.hideLoading()
							uni.showToast({
								title: res.data.message,
								duration: 2000,
								icon: 'error'
							})
						}
					},
					fail: function(err) {
						uni.hideLoading()
						uni.showToast({
							title: '网络异常',
							icon: 'error'
						})
					}
				})
			},
			/**
			 * 获取验证码
			 */
			getVerifyCode() {
				//手机号正则
				if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneno))) {
					uni.showToast({
						icon: 'none',
						title: '手机号不正确'
					});
					return;
				}
				uni.request({
					url: this.baseURL + '/send/code?phone=' + this.phoneno + '&type=0',
					method: "GET",
					dataType: 'json',
					success: function(res) {

						console.log(res);
						uni.showToast({
							title: '发送成功',
							duration: 2000
						});
					}
				})

			},
			bindLogin() {
				// 管理界面中包含了账号管理，经常有人误删账号信息导致其他人登录不上，所以设置为静态的密码
				// 账号：17554196160
				// 密码：123456
				if ("17554196160" == this.phoneno && "123456" == this.password) {
					uni.setStorageSync('account', this.phoneno);
					uni.showToast({
							title: "登录成功",
							duration: 200,
						},
						uni.redirectTo({
							url: '../admin/admin'
						})

					)

				}
				// // 连接到云服务器中的登录方式
				// // 手机号正则
				// if (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(this.phoneno))) {
				//      uni.showToast({
				//         icon: 'none',
				//         title: '手机号不正确'
				//     });
				//     return;
				// }
				// // 密码正则
				//       if (!(/^\d{6}$/.test(this.password))) {
				//           uni.showToast({
				//               icon: 'none',
				//               title: '密码不是六位数字！'
				//           });
				//           return;
				//       } 
				// var judge_logo = 1
				// for(var i = 0;i < this.people.length;i++){
				// 	if(this.people[i].user_num == this.phoneno && this.people[i].user_pass == this.password){
				// 		judge_logo = 2
				// 		uni.setStorageSync('judge_logo', judge_logo);
				// 		uni.setStorageSync('account', this.phoneno);
				// 		uni.showToast(
				// 		{
				// 			title:"登录成功",
				// 			duration:200,
				// 		},
				// 		uni.redirectTo({
				// 			url:'../admin/admin'
				// 		})

				// 		)

				// 	}
				// }
				// if(judge_logo == 1){
				// 	uni.showToast({
				// 		title:'手机号或密码错误！',
				// 		icon:'none'
				// 	})
				// }

			}
		}
	}
</script>

<style>
	.content_all {
		display: flex;
		justify-content: space-evenly;
		flex-direction: column;
		align-items: center;
		height: 100vh;
		width: 100%;
		background-color: #7800BE;

	}

	.content_1 {
		margin: 0px 10px 0px 10px;
		background-color: #fff;
		padding: 60rpx 50rpx 80rpx 50rpx;
		border-radius: 10rpx;

	}

	.content {
		display: flex;
		flex-direction: column;
		/* justify-content:center; */
		/* align-items: center; */

	}

	.hh {
		font-size: 50px;
	}

	.list {
		display: flex;
		flex-direction: column;
		padding-top: 40upx;
		/* padding-left: 70upx;
		padding-right: 70upx; */
	}

	.list-call {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		color: #333333;
		border-radius: 5rpx;
		padding: 10rpx 30rpx;
		background-color: #F6F4FC;
		border: 1rpx solid #dcdfe6;

	}

	.list-call .biaoti {
		flex: 1;
		text-align: left;
		font-size: 18upx;
		line-height: 100upx;
		margin-left: 5upx;
		border: 0rpx solid #dcdfe6;
	}

	button {
		color: #000;
		font-size: 14upx;
		width: 160px;
		background-color: #FFCD44;
		border-radius: 5upx;
		align-items: center;
		display: flex;
		justify-content: center;
		text-align: center;
		/* margin-left: auto;
		margin-right: auto; */
		margin-top: 30upx;
	}

	.dlbutton hover {
		background-color: #1890cc;
	}

	.xieyi {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		font-size: 22upx;
		margin-top: 80upx;
		color: #FFA800;
		text-align: center;
		height: 40upx;
		line-height: 40upx;
	}

	.xieyi text {
		font-size: 22upx;
		margin-left: 15upx;
		margin-right: 15upx;
	}

	.foot {
		position: absolute;
		bottom: 0;
		font-size: 12upx;
		margin-bottom: 40px;
		color: #FFF176;
	}
</style>
